feat: add VZVmnetNetworkDeviceAttachment support (macOS 26.0) - #205
norio-nomura wants to merge 15 commits into
Conversation
VmnetNetworkDeviceAttachment support (macOS 26.0)VZVmnetNetworkDeviceAttachment support (macOS 26.0)
6617c8f to
6a1f741
Compare
Based on `VMNET_SHARED_MODE`, and `VMNET_HOST_MODE` ```yaml networks: - vzShared: true - vzHost: true ``` But, to sharing network between multiple VMs, `VZVmnetNetworkDeviceAttachment` requires VMs are launched by same process. It depends on Code-Hex/vz#205 Signed-off-by: Norio Nomura <norio.nomura@gmail.com>
|
This can be used by multiple processes like this:
|
5a7a116 to
72cc1d4
Compare
In this procedure, I confirmed that VMs launched from multiple processes can share networks with each other. 👍🏻 |
72cc1d4 to
9506cbd
Compare
Added unit test and |
I'll try this added xpc package with lima to make it work. Until then, it's a draft. |
7bf24c1 to
007c2a5
Compare
Based on `VMNET_SHARED_MODE`, and `VMNET_HOST_MODE` ```yaml networks: - vzShared: true - vzHost: true ``` But, to sharing network between multiple VMs, `VZVmnetNetworkDeviceAttachment` requires VMs are launched by same process. It depends on Code-Hex/vz#205 Signed-off-by: Norio Nomura <norio.nomura@gmail.com>
aba95bd to
ba619f5
Compare
d3fad75 to
7a58378
Compare
Based on `VMNET_SHARED_MODE`, and `VMNET_HOST_MODE` ```yaml networks: - vzShared: true - vzHost: true ``` But, to sharing network between multiple VMs, `VZVmnetNetworkDeviceAttachment` requires VMs are launched by same process. It depends on Code-Hex/vz#205 Signed-off-by: Norio Nomura <norio.nomura@gmail.com>
7a58378 to
33858c0
Compare
nirs
left a comment
There was a problem hiding this comment.
I did not review most of this change, just the stange part of about marking bridged mode as depracated.
f048f6e to
3b512d7
Compare
Based on `VMNET_SHARED_MODE`, and `VMNET_HOST_MODE` ```yaml networks: - vzShared: true - vzHost: true ``` But, to sharing network between multiple VMs, `VZVmnetNetworkDeviceAttachment` requires VMs are launched by same process. It depends on Code-Hex/vz#205 Signed-off-by: Norio Nomura <norio.nomura@gmail.com>
To avoid crash when `Context` is canceled before receiving reply. Signed-off-by: Norio Nomura <norio.nomura@gmail.com>
9241433 to
ec911e3
Compare
`vmnet`: Fix golangci-lint-v2 violations
`vmnet`: if iface.EnableVirtioHeader { packetSize += virtioNetHdrSize }
`vmnet`: Remove `object`
`vmnet`: Add doc comments to `*FileAdapterForInterface`s
`vmnet`: Refactor `*FileAdapterForInterface`s
- Remove written packet count from result of `WritePacketsTo*` in `PacketForwarder`
- Minimize differences between `pktDescsManager` and `msgHdrXArray`
`vmnet`: Handle `syscall.ENOBUFS` in `DatagramPacketForwarder.WritePacketsToConn`
`syscall.Sendmsg` may return `syscall.ENOBUFS` if there is not enough buffer set to the destination.
Signed-off-by: Norio Nomura <norio.nomura@gmail.com>
- `StreamFileAdapterForInterface`: - Support partial read on `unix.Readv` in `readPacketsFromConn` - `Datagram*FileAdapterForInterface`: - Add wait on `syscall.ENOBUFS` in `writePacketsToPacketConn` Signed-off-by: Norio Nomura <norio.nomura@gmail.com>
Signed-off-by: Norio Nomura <norio.nomura@gmail.com>
Signed-off-by: Norio Nomura <norio.nomura@gmail.com>
Use `*FileAdapterForInterface` APIs in `TestVmnetSharedModeAllowsCommunicationBetweenMultipleVMs`: - `datagram.FileAdapterForInterface` - `datagramx.FileAdapterForInterface` Since they are compatible with `vz.NewFileHandleNetworkDeviceAttachment`. Signed-off-by: Norio Nomura <norio.nomura@gmail.com>
ec911e3 to
e27a5fb
Compare
Based on `VMNET_SHARED_MODE`, and `VMNET_HOST_MODE` ```yaml networks: - vzShared: true - vzHost: true ``` But, to sharing network between multiple VMs, `VZVmnetNetworkDeviceAttachment` requires VMs are launched by same process. It depends on Code-Hex/vz#205 Signed-off-by: Norio Nomura <norio.nomura@gmail.com> # Conflicts: # go.sum # Conflicts: # go.sum
| if !netip.MustParsePrefix("192.168.0.0/16").Overlaps(subnet) { | ||
| return fmt.Errorf("subnet %s is out of range", subnet.String()) | ||
| } |
There was a problem hiding this comment.
Is there any specific reason for limiting to the 192.168.0.0/16 range only? Ideally users should be able to specify any RFC 1918 range, including 10.0.0.0/8 or 172.16.0.0/12 and it doesnt look like apple explicitly prevents this.
| if !netip.MustParsePrefix("192.168.0.0/16").Overlaps(subnet) { | |
| return fmt.Errorf("subnet %s is out of range", subnet.String()) | |
| } | |
| rfc1918 := []netip.Prefix{ | |
| netip.MustParsePrefix("10.0.0.0/8"), | |
| netip.MustParsePrefix("172.16.0.0/12"), | |
| netip.MustParsePrefix("192.168.0.0/16"), | |
| } | |
| allowed := false | |
| for _, r := range rfc1918 { | |
| if r.Overlaps(subnet) { | |
| allowed = true | |
| break | |
| } | |
| } | |
| if !allowed { | |
| return fmt.Errorf("subnet %s is not in an RFC 1918 range", subnet.String()) | |
| } |
There was a problem hiding this comment.
The docs say a /24 under 192.168/16.
https://developer.apple.com/documentation/vmnet/vmnet_network_configuration_create(_:_:)
There was a problem hiding this comment.
According to the doc, it is a default value.
All other parameters are optional and have the following default value:
...
There was a problem hiding this comment.
Right, good chance that it supports the same private addresses as the older APIs.
|
@norio-nomura any progress here, if you can list some of the changes you are looking for, i am happy to assist i making them and the adding then opening a pr to this. |
|
Played with this a bit, specifically with
And I can confirm that at least this flow works fine and there is no need for root if below entitlements are used alongside with Hoping we get this merged before macOS 27.0 comes out, as it will also ship more new features. One thing that I've noticed is that |
|
@norio-nomura Could you share the current status of this PR and what remains before it is ready for review? In February, you mentioned testing the file adapter in Lima and investigating the TSO issue. Are those still the main blockers? No rush; I want to understand the next steps and whether a smaller part is ready to review separately. |
feat: add
VZVmnetNetworkDeviceAttachmentsupport (macOS 26.0)VZVmnetNetworkDeviceAttachmentis an API that creates vmnet devices on VMs added in macOS 26.see: https://developer.apple.com/documentation/virtualization/vzvmnetnetworkdeviceattachment?language=objc
It does not require the
com.apple.vm.networkingentitlement nor root privileges.HostModeandSharedModeare supported.In order for multiple VMs to communicate with each other in
SharedMode, they must be started in the same executable and the sameVmnetNetworkmust be passed toNewVmnetNetworkDeviceAttachment()to create an attachment.This change adds:
vz.VmnetNetworkDeviceAttachmentrepresentsVZVmnetNetworkDeviceAttachmentin Govmnetpackage to use vmnet APIs that added on macOS 26.0Returnrepresentsvmnet_return_taserrorErrSuccess,ErrFailure, ...Moderepresentsoperating_modes_tHostMode,SharedModeNetworkConfigurationrepresentsvmnet_network_configuration_tNetworkrepresentsvmnet_network_refInterfacerepresentsinterface_ref*FileAdaptorForInterfaces support File Handle based network device APIs on QEMU, krunkit, andvz.NewFileHandleNetworkDeviceAttachmentxpcpackage that providing<xpc/xpc.h>APIs to support implementing Mach service server/client to sharing serializations ofvmnet.Networkand file descriptors ofvmnet.*FileAdaptorForInterfacesvz_test.TestVmnetSharedModeAllowsCommunicationBetweenMultipleVMsvz_test.TestVmnetSharedModeWithConfiguringIPv4vz_test.TestVmnetNetworkShareModeSharingOverXpcTestVmnetNetworkShareModeSharingOverXpctests sharingvmnet.NetworkinSharedModeover XPC communication.This test registers test executable as an Mach service and launches it using
launchctl.The launched Mach service provides
vmnet.Networkserialization to clients upon request, after bootinga VM using the provided
vmnet.Networkto ensure the network is functional on the server side.The client boots VM using the provided
vmnet.Networkserialization.Edit: on macOS 26.2, "the same executable" restriction seems to be relaxed.
VZVmnetNetworkDeviceAttachmentseems to allow connecting to subnet created by a different executable.vmnet_interface_start_with_networkseems to allow connecting to subnet created by an executable at same path? (may changing CDHash not affect?)Which issue(s) this PR fixes:
Mentioned in #198 (comment)